#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e5;
int a[N + 10];
int x, y;
int ret;
void bfs()
{
    queue<int> as;
    as.push(x);
    a[x] = 0;
    while (as.size())
    {
        int r = as.front();
        as.pop();
        int z = r + 1;
        int h = r - 1;
        int c = 2 * r;
        if (z < N && a[z] == -1)
        {
            a[z] = a[r] + 1;
            as.push(z);
        }
        if (h > 0 && a[h] == -1)
        {
            a[h] = a[r] + 1;
            as.push(h);
        }
        if (c < N && a[c] == -1)
        {
            a[c] = a[r] + 1;
            as.push(c);
        }
        if (z == y || h == y || c == y)
        {
            return;
        }
    }
}
int main()
{
    int t = 0;
    cin >> t;
    while (t--)
    {
        memset(a, -1, sizeof(a));
        cin >> x >> y;
        bfs();
        cout << a[y] << endl;
    }
    return 0;
}